package com.intellij.licensecommon.f.impl;

import com.intellij.licensecommon.data.LicenseImpl;
import com.intellij.licensecommon.f.b;
import com.intellij.licensecommon.message.Message;
import com.intellij.licensecommon.message.impl.LicenseMessageData;
import org.jdom.Attribute;
import org.jdom.DataConversionException;
import org.jdom.Element;
import org.jetbrains.annotations.Nullable;

class e extends Constants {
    private static final int m = 1;

    public static Message a(Element paramElement)
            throws b {
        String str = paramElement.getName();
        if (str.equals("U")) {
            return d(paramElement);
        }
        if (str.equals("licenseUnused")) {
            return e(paramElement);
        }
        throw new b("Unsupported XML structure: " + str);
    }

    private static LicenseMessageData b(Element paramElement) {
        int i = c(paramElement);
        String str = a(paramElement, i);
        LicenseImpl localf = b(paramElement, i);
        return new c(i, str, localf);
    }

    private static int c(Element paramElement) {
        Attribute localAttribute = paramElement.getAttribute("v");
        if (localAttribute == null) {
            return 1;
        }
        int i;
        try {
            i = localAttribute.getIntValue();
        } catch (DataConversionException localDataConversionException) {
            return 1;
        }
        if (i <= 0) {
            return 1;
        }
        return i;
    }

    @Nullable
    private static String a(Element paramElement, int paramInt) {
        if (paramInt == 1) {
            localObject = paramElement.getChild("tag");
            if (localObject == null) {
                return null;
            }
            return ((Element) localObject).getTextTrim();
        }
        Object localObject = paramElement.getAttribute("i");
        if (localObject == null) {
            return null;
        }
        return ((Attribute) localObject).getValue().trim();
    }

    @Nullable
    private static LicenseImpl b(Element paramElement, int paramInt) {
        if (paramInt == 1) {
            localElement = paramElement.getChild("license");
            if (localElement == null) {
                return null;
            }
            localObject1 = localElement.getChild("name");
            localObject2 = localElement.getChild("key");
            if ((localObject1 == null) || (localObject2 == null)) {
                return null;
            }
            return new LicenseImpl(((Element) localObject1).getText(), ((Element) localObject2).getText());
        }
        Element localElement = paramElement.getChild("L");
        if (localElement == null) {
            return null;
        }
        Object localObject1 = localElement.getAttribute("n");
        Object localObject2 = localElement.getAttribute("k");
        if ((localObject1 == null) || (localObject2 == null)) {
            return null;
        }
        return new LicenseImpl(((Attribute) localObject1).getValue().trim(), ((Attribute) localObject2).getValue().trim());
    }

    private static com.intellij.licensecommon.message.impl.d d(Element paramElement) {
        return new com.intellij.licensecommon.message.impl.d(b(paramElement));
    }

    private static com.intellij.licensecommon.message.impl.c e(Element paramElement) {
        return new com.intellij.licensecommon.message.impl.c(b(paramElement));
    }
}

